workflowModule.controller("WorkflowManagementApprovalCtrl", ["$log", "$q", "$scope", "$timeout", "$filter", "workflowSvc", "dataDicSvc", "aresNotification", "workflowBaseToolUtil", "enums", "aresDialog", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    var v = function() {
            var n = Ares.today(),
                t = moment(Ares.today()).startOf("month").toDate(),
                r = {
                    startDate: t,
                    endDate: n
                };
            i.timeSpan = _.clone(r)
        },
        y = function(n) {
            n == "previous" ? (i.timeSpan.startDate = moment(i.timeSpan.startDate).add(-1, i.selectDate).startOf(i.selectDate).toDate(), i.timeSpan.endDate = moment(i.timeSpan.endDate).add(-1, i.selectDate).endOf(i.selectDate).toDate()) : n == "next" && (i.timeSpan.startDate = moment(i.timeSpan.startDate).add(1, i.selectDate).startOf(i.selectDate).toDate(), i.timeSpan.endDate = moment(i.timeSpan.endDate).add(1, i.selectDate).endOf(i.selectDate).toDate());
            l()
        },
        p = function(n) {
            switch (n) {
                case "all":
                    i.timeSpan.startDate = null;
                    i.timeSpan.endDate = null;
                    i.selectDate = "all";
                    break;
                case "day":
                    i.timeSpan.startDate = moment(Ares.today()).toDate();
                    i.timeSpan.endDate = moment(Ares.today()).toDate();
                    i.selectDate = "day";
                    break;
                case "week":
                    i.timeSpan.startDate = moment(Ares.today()).startOf("week").toDate();
                    i.timeSpan.endDate = moment(Ares.today()).endOf("week").toDate();
                    i.selectDate = "week";
                    break;
                case "month":
                    i.timeSpan.startDate = moment(Ares.today()).startOf("month").toDate();
                    i.timeSpan.endDate = moment(Ares.today()).endOf("month").toDate();
                    i.selectDate = "month";
                    break;
                case "custom":
                    i.timeSpan.endDate || v();
                    i.selectDate = "custom"
            }
            l()
        },
        w = function() {
            i.searchCriteria = {
                startTime: null,
                endTime: null,
                workflowType: "all",
                taskStatus: "all"
            };
            i.page = {
                index: 1,
                size: 15
            };
            i.selectDate = "all";
            i.timeSpan = {}
        },
        b = function() {
            var n = t.defer();
            return e.workflowTypeDic.load().then(function(t) {
                i.workflowTypes = [{
                    workflowType: "all",
                    typeName: "全部"
                }];
                i.workflowTypes = i.workflowTypes.concat(t);
                n.resolve()
            }), i.workflowTaskStatusList = [{
                name: "全部",
                value: "all"
            }, {
                name: "待审批",
                value: "0"
            }, {
                name: "已批准",
                value: "1"
            }, {
                name: "已拒绝",
                value: "2"
            }, ], n.promise
        },
        k = function(n) {
            Ares.specificOfficeUtil.enter(n.officeId);
            f.approve(n).then(function() {
                Ares.specificOfficeUtil.exit();
                o.success("批准成功");
                l()
            }).catch(function() {
                Ares.specificOfficeUtil.exit();
                o.error("批准失败")
            })
        },
        d = function(n) {
            Ares.specificOfficeUtil.enter(n.officeId);
            f.reject(n).then(function() {
                Ares.specificOfficeUtil.exit();
                o.success("拒绝成功");
                l()
            }).catch(function() {
                Ares.specificOfficeUtil.exit();
                o.error("拒绝失败")
            })
        },
        g = function(n) {
            Ares.specificOfficeUtil.enter(n.officeId);
            f.revert(n).then(function() {
                Ares.specificOfficeUtil.exit();
                o.success("撤回成功");
                l()
            }).catch(function() {
                Ares.specificOfficeUtil.exit();
                o.error("撤回失败")
            })
        },
        l = function() {
            a();
            f.getWorkflowItemBySearchCriteria(i.searchCriteria).then(function(n) {
                var t = n.data;
                i.approvalList = t.items;
                i.approvalList.forEach(function(n, t) {
                    tt(n, t)
                });
                i.page.count = t.pageCount;
                i.page.size = t.pageSize;
                i.page.index = t.pageIndex;
                i.page.totalCount = t.totalCount;
                r(function() {
                    i.initView()
                })
            })
        },
        nt = function() {
            var t;
            a();
            t = {
                criteria: i.searchCriteria,
                columns: [{
                    hidden: !1,
                    field: "ApplicationTime",
                    title: "申请时间"
                }, {
                    hidden: !1,
                    field: "Applicant",
                    title: "申请人"
                }, {
                    hidden: !1,
                    field: "OfficeName",
                    title: "诊所"
                }, {
                    hidden: !1,
                    field: "WorkflowType",
                    title: "类型"
                }, {
                    hidden: !1,
                    field: "TaskStatus",
                    title: "状态"
                }, {
                    hidden: !1,
                    field: "TaskExecutionTime",
                    title: "审批时间"
                }, {
                    hidden: !1,
                    field: "TaskExecutorName",
                    title: "审批人"
                }, {
                    hidden: !1,
                    isAutoWrap: !0,
                    field: "TaskNotes",
                    title: "备注"
                }]
            };
            f.exportExcel(t).then(function(n) {
                var t = n.data.url;
                Ares.download(t);
                n.data.isOverflow && c.confirm("提示", "审批数据超过限制，只导出部分数据，创建我的报表，是否继续？").then(function() {
                    f.createWorkflowExportBackground(i.searchCriteria).success(function(n) {
                        var t = n.isSucceed ? n.hasTaskCancelled ? "后台报表'" + n.newTask.reportName + "'已创建！（已取消10分钟内同类报表）" : "后台报表'" + n.newTask.reportName + "'已创建！" : "已存在处理的同类型的报表（10分钟内只能创建一个同类型报表）！";
                        c.info("信息", t)
                    })
                })
            }, function() {
                n.error(err);
                o.error("导出失败")
            })
        },
        a = function() {
            i.searchCriteria.startTime = i.timeSpan.startDate;
            i.searchCriteria.endTime = i.timeSpan.endDate ? moment(i.timeSpan.endDate).add(1, "day").format("YYYY-MM-DD") : i.timeSpan.endDate;
            i.searchCriteria.pageIndex = i.page.index;
            i.searchCriteria.pageSize = i.page.size
        },
        tt = function(n, t) {
            n.index = t + 1;
            n.approverName = n.taskExecutorName;
            !n.taskExecutorName && n.taskExecutors && (n.approverName = n.taskExecutors.map(function(n) {
                return n.executorName
            }).join("，"));
            n.applyDateTimeStr = moment(n.applicationTime).format("YYYY-MM-DD HH:mm:ss");
            n.taskExecutionTime && (n.approvalDateTimeStr = moment(n.taskExecutionTime).format("YYYY-MM-DD HH:mm:ss"));
            n.notes = n.taskNotes;
            var r = _.find(i.workflowTypes, function(t) {
                return t.workflowType == n.workflowType
            });
            r && (n.workflowTypeStr = r.typeName);
            n.taskStatusStr = s.getWorkflowTaskStatusDescription(n)
        };
    (function() {
        i.switchDate = p;
        i.updateDate = y;
        i.searchApprovalPageList = l;
        i.approve = k;
        i.reject = d;
        i.revert = g;
        i.exportExcel = nt;
        b().then(function() {
            w();
            l()
        })
    })()
}]);
workflowModule.controller("WorkflowSettingApprovalCtrl", ["$log", "$q", "$scope", "$timeout", "$filter", "workflowSvc", "loginContext", "aresNotification", "dataDicSvc", "aresDialog", "enums", "permissionProvider", "officeUtil", function(n, t, i, r, u, f, e, o, s, h, c, l, a) {
    "use strict";
    var y = {
            money: "元",
            percent: "%"
        },
        p = {
            "approvement.deductionCallback": c.WorkflowType.DeductionStepRevert,
            "approvement.deductionComplete": c.WorkflowType.DeductionStepFinish,
            "approvement.deductionSkip": c.WorkflowType.DeductionStepSkip,
            "approvement.take": c.WorkflowType.InventoryTake,
            "approvement.charge": c.WorkflowType.Charge,
            "approvement.refund": c.WorkflowType.ChargeRefund,
            "approvement.procurement": c.WorkflowType.ProcurementPay
        },
        w = function(n) {
            var i = t.defer();
            return f.checkIsAllowedDeleteDefinition(n).success(function(t) {
                t === !0 ? h.confirm("提示", "确定要删除此审批配置？").then(function() {
                    return f.deleteDefinition(n)
                }).then(function() {
                    return o.success("删除成功"), s.workflowDefinitionDic.clearCache(), v()
                }).then(function() {
                    i.resolve()
                }) : (o.error("还有未完成的审批任务，不允许删除！"), i.resolve())
            }), i.promise
        },
        b = function() {
            var n = [],
                t, r;
            i.isInternWorkflowEnabled || (t = [c.WorkflowType.InstructorCharge, c.WorkflowType.InstructorMedicalRecord, c.WorkflowType.InstructorDrugOrder], n = n.concat(t));
            i.isDeductionChargeEnabled || (r = [c.WorkflowType.DeductionStepFinish, c.WorkflowType.DeductionStepRevert, c.WorkflowType.DeductionStepSkip], n = n.concat(r));
            _.each(p, function(t, i) {
                l.isAllowed(i) || n.push(t)
            });
            i.isProcurementApplyEnabled || n.push(c.WorkflowType.ProcurementApply);
            i.workflowTypes = i.workflowTypes.filter(function(t) {
                return n.indexOf(t.workflowType) == -1
            })
        },
        k = function() {
            var n = [];
            return n.push(s.workflowTypeDic.load().then(function(n) {
                i.workflowTypes = n
            })), n.push(s.officeSettingDic.load().then(function(n) {
                i.isInternWorkflowEnabled = n.isInternWorkflowEnabled;
                i.isDeductionChargeEnabled = n.isDeductionChargeEnabled
            })), n.push(s.officeSettingDic.load().then(function(n) {
                i.isInternWorkflowEnabled = n.isInternWorkflowEnabled;
                i.isDeductionChargeEnabled = n.isDeductionChargeEnabled
            })), n.push(a.getGroupProcurementMethod().then(function(n) {
                i.isProcurementApplyEnabled = n !== "self"
            })), n.push(s.workflowOperatorDic.load().then(function(n) {
                i.workflowOperators = n
            })), n.push(s.workflowCondFieldDic.load().then(function(n) {
                i.workflowCondFields = n
            })), n.push(s.workflowApprovalProviderDic.loadActive().then(function(n) {
                n.forEach(function(n) {
                    n.displayName = n.officeId == e.officeId ? n.name : n.name + "(" + n.officeAbbreviation + ")"
                });
                i.allProviders = n
            })), t.all(n)
        },
        d = function(n) {
            var t = i.workflowTemplateList;
            return n && n.id && (t = i.workflowTemplateList.filter(function(t) {
                return t.id != n.id
            })), i.workflowTypes
        },
        v = function() {
            var n = t.defer();
            return i.workflowTemplateList = [], s.workflowDefinitionDic.load().then(function(t) {
                t && t.length && (i.workflowTemplateList = _.sortBy(t, function(n) {
                    return n.workflowType
                }));
                i.workflowTemplateList.forEach(function(n) {
                    n.steps.forEach(function(n) {
                        n.actors.sort(function(n, t) {
                            return n.id - t.id
                        })
                    });
                    var t = _.find(i.workflowTypes, function(t) {
                        return t.workflowType == n.workflowType
                    });
                    t && (n.workflowTypeStr = t.typeName);
                    n.conds && n.conds.length > 0 && n.conds.forEach(function(n) {
                        var t = _.find(i.workflowCondFields, function(t) {
                            return t.fieldCode == n.fieldCode
                        });
                        n.fieldName = t.fieldName;
                        n.fieldTypeName = t.fieldTypeName;
                        n.fieldUnit = y[n.fieldTypeName];
                        n.fieldOperators = _.find(i.workflowOperators, function(t) {
                            return t.fieldCode == n.fieldCode
                        }).condOperators;
                        n.operator ? n.operatorName = n.fieldTypeName != "event" ? _.find(n.fieldOperators, function(t) {
                            return t.operatorCode == n.operator
                        }).operatorName : "" : (n.operator = n.fieldOperators[0].operatorCode, n.operatorName = n.fieldOperators[0].operatorName)
                    })
                });
                i.workflowTemplateList = i.workflowTemplateList.filter(n => n.workflowTypeStr);
                n.resolve()
            }), b(), n.promise
        },
        g = function() {
            return k().then(function() {
                return v()
            })
        },
        nt = function(n) {
            f.updateDefinition(n).then(function() {
                s.workflowDefinitionDic.clearCache();
                o.success("操作成功")
            })
        };
    (function() {
        i.getCanAddWorkflowTypes = d;
        i.removeTemplateItem = w;
        i.initWorkflowTemplates = v;
        i.onSwitchChanged = nt;
        g().then(function() {
            r(function() {
                i.initView()
            })
        })
    })()
}]);
workflowModule.directive("workflowApprovalSettingItemView", ["$log", "$q", "$timeout", "$filter", "aresNotification", "enums", function(n, t, i, r, u, f) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/workflow/dialogs/workflow-approval-setting-item/workflow-approval-setting-item-view.html",
        link: function(n, t) {
            var o = function(n) {
                    return r("toMoney")(n)
                },
                s = function() {
                    n.itemInfo.isEdit = !0;
                    i(function() {
                        Ares.centerModal(t.closest(".modal-dialog"))
                    }, 30)
                },
                h = function() {
                    var i, t;
                    if (c(), n.itemInfo.steps[0].actors.length == 0 && (i = [f.WorkflowType.InstructorCharge, f.WorkflowType.InstructorMedicalRecord, f.WorkflowType.InstructorDrugOrder], i.indexOf(n.itemInfo.workflowType) == -1)) return u.error("缺少审批人"), !1;
                    if (n.hasWorkflowConds) {
                        if (n.itemInfo.conds.length == 0) return u.error("缺少审批条件"), !1;
                        if (!n.itemInfo.conds.some(function(n) {
                                return !!n.benchmark || parseFloat(n.benchmark) == 0
                            })) return u.error("审批条件缺少内容"), !1;
                        if (t = !1, n.itemInfo.conds.forEach(function(i) {
                                var r = n.itemInfo.conds.filter(function(n) {
                                    return n.fieldCode == i.fieldCode
                                }).length;
                                r > 1 && (t = !0)
                            }), t) return u.error("审批条件类型不能重复"), !1
                    }
                    n.itemInfo.id > 0 ? n.updateWorkflowTemplateItem() : n.createWorkflowTemplateItem()
                },
                c = function() {
                    _(n.itemInfo.steps).each(function(t) {
                        t.actors = _(t.actors).filter(function(t) {
                            return _(n.providers).any(function(n) {
                                return n.userId == t.actorId
                            })
                        })
                    })
                },
                e = function() {
                    if (n.currentWorkflowCondFields.length > 0 && n.itemInfo.conds.length >= n.currentWorkflowCondFields.length) {
                        u.error("触发条件最多" + n.currentWorkflowCondFields.length + "条");
                        return
                    }
                    if (n.currentWorkflowCondFields[0]) {
                        var t = {
                            fieldCode: n.currentWorkflowCondFields[0].fieldCode
                        };
                        n.initDisplayCondInfo(t);
                        t.benchmark = t.fieldTypeName == "money" || t.fieldTypeName == "percent" ? 0 : t.fieldTypeName == "event" ? 1 : "";
                        n.itemInfo.conds.push(t)
                    }
                },
                l = function(t) {
                    n.itemInfo.conds.splice(t, 1)
                },
                a = function() {
                    return {
                        isBrowseMethod: function() {
                            return !1
                        },
                        onChange: function(t, i, r) {
                            n.initCondFieldDetailInfo(r)
                        }
                    }
                },
                v = function() {
                    return {
                        isBrowseMethod: function() {
                            return !1
                        },
                        onChange: function(t, i, r) {
                            n.initCondOperatorInfo(r);
                            r.benchmark = 0;
                            r.benchmarkMax = 0
                        }
                    }
                },
                y = function() {
                    return {
                        onChange: function(t, r) {
                            i(function() {
                                var t = r.workflowType;
                                n.initApprovers(t);
                                n.hasWorkflowConds = n.getHasWorkflowConds(t);
                                n.currentWorkflowCondFields = n.getCurrentWorkflowCondFields(t);
                                n.itemInfo.conds = [];
                                e()
                            })
                        }
                    }
                },
                p = function() {
                    return {
                        isBrowseMethod: function() {
                            return !1
                        }
                    }
                },
                w = function() {
                    return {
                        getDefaultMaxMethod: function() {
                            return 9999999
                        },
                        getDefaultMinMethod: function() {
                            return 0
                        },
                        onChange: function(n, t, r, u) {
                            if (u.operator == 7 && parseFloat(n) > parseFloat(u.benchmarkMax)) {
                                var f = parseFloat(u.benchmarkMax);
                                i(function() {
                                    n > f && (u.benchmarkMax = n)
                                })
                            }
                        }
                    }
                },
                b = function() {
                    return {
                        getDefaultMaxMethod: function() {
                            return 100
                        },
                        getDefaultMinMethod: function() {
                            return 0
                        },
                        onChange: function(n, t, r, u) {
                            if (u.operator == 7 && parseFloat(n) > parseFloat(u.benchmarkMax)) {
                                var f = parseFloat(u.benchmarkMax);
                                i(function() {
                                    n > f && (u.benchmarkMax = n)
                                })
                            }
                        }
                    }
                },
                k = function() {
                    return {
                        getDefaultMaxMethod: function() {
                            return 9999999
                        },
                        getDefaultMinMethod: function() {
                            return 0
                        },
                        onChange: function(n, t, r, f) {
                            var e = parseFloat(f.benchmark);
                            parseFloat(n) < e && i(function() {
                                u.error("最大值能小于" + e);
                                f.benchmarkMax = t || e + 1
                            })
                        }
                    }
                },
                d = function() {
                    return {
                        getDefaultMaxMethod: function() {
                            return 100
                        },
                        getDefaultMinMethod: function() {
                            return 0
                        },
                        onChange: function(n, t, r, f) {
                            var e = parseFloat(f.benchmark);
                            parseFloat(n) < e && (u.error("最大值能小于" + e), i(function() {
                                f.benchmarkMax = t || e + 1
                            }))
                        }
                    }
                },
                g = function(n) {
                    if (!n) return "";
                    var t = "";
                    return n.fieldTypeName == "money" ? t = n.benchmark ? o(n.benchmark) : "0.00" : n.fieldTypeName == "percent" && (t = n.benchmark ? n.benchmark : "0"), t.trim() + n.fieldUnit
                },
                nt = function() {
                    if (n.itemInfo.steps.length >= 10) {
                        u.error("最多添加10级审批人");
                        return
                    }
                    var t = {
                        actors: [],
                        isNeedRemind: !0,
                        stepIndex: n.itemInfo.steps.length + 1
                    };
                    n.itemInfo.steps.push(t)
                },
                tt = function(t) {
                    n.itemInfo.steps.splice(t, 1);
                    _.each(n.itemInfo.steps, function(n, t) {
                        n.stepIndex = t + 1
                    })
                },
                it = function(t, i) {
                    if (t !== 0) {
                        var r = i[t];
                        n.itemInfo.steps[t].stepIndex = r.stepIndex - 1;
                        n.itemInfo.steps[t - 1].stepIndex = i[t - 1].stepIndex + 1;
                        n.itemInfo.steps.splice(t, 1);
                        n.itemInfo.steps.splice(t - 1, 0, r)
                    }
                },
                rt = function(t, i) {
                    if (t !== i.length - 1) {
                        var r = i[t];
                        n.itemInfo.steps[t].stepIndex = r.stepIndex + 1;
                        n.itemInfo.steps[t + 1].stepIndex = i[t + 1].stepIndex - 1;
                        n.itemInfo.steps.splice(t, 1);
                        n.itemInfo.steps.splice(t + 1, 0, r)
                    }
                },
                ut = function() {
                    n.selectOptions = {
                        placeholder: "请选择需要审批的员工",
                        dataTextField: "actorName",
                        dataValueField: "actorId",
                        dataSource: n.providers,
                        maxSelectedItems: 9,
                        itemTemplate: '<span class="option-item">#:employeeNo #<\/span><span class="option-item">#:actorName #<\/span><span class="option-item">#:officeAbbreviation #<\/span><span class="option-item">#:job #<\/span>'
                    }
                };
            (function() {
                n.saveEdit = h;
                n.operatorDropDownListOption = v();
                n.condFieldDropDownListOption = a();
                n.benchmarkPercentOption = b();
                n.benchmarkMoneyOption = w();
                n.benchmarkMaxPercentOption = d();
                n.benchmarkMaxMoneyOption = k();
                n.approvalActorsMultiSelectOptions = p();
                n.workflowTypeDropDownListOption = y();
                n.addCondItem = e;
                n.deleteCondItem = l;
                n.getDisplayBenchmark = g;
                n.addStepItem = nt;
                n.deleteStepItem = tt;
                n.upStepItem = it;
                n.downStepItem = rt;
                n.actionName = "";
                n.initWorkflowConfig().then(function() {
                    n.initWorkflowInfo();
                    n.itemInfo.conds && n.itemInfo.conds.length > 0 && n.itemInfo.conds.forEach(function(t) {
                        n.initDisplayCondInfo(t)
                    });
                    n.actionName = n.itemInfo.id > 0 ? "编辑" : "新增";
                    ut()
                }).then(function() {
                    s()
                })
            })()
        }
    }
}]);
workflowModule.controller("WorkflowApprovalSettingItemCtrl", ["$log", "$q", "$scope", "$timeout", "$filter", "$modalInstance", "dataDicSvc", "host", "enums", "workflowSvc", "aresNotification", "loginContext", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    var d = function() {
            f.dismiss()
        },
        a = function() {
            var n = angular.copy(i.itemInfo);
            return n.conds && n.conds.length > 0 && n.conds.forEach(function(n) {
                if (n.operator == 7) {
                    var t = n.benchmarkMax ? n.benchmarkMax : 9999999;
                    n.benchmark = n.benchmark + "," + t
                }
            }), n
        },
        g = function() {
            var n = t.defer(),
                i = a();
            return h.updateDefinition(i).then(function(t) {
                var i = t.data;
                c.success("保存成功");
                e.workflowDefinitionDic.clearCache();
                f.close(i);
                n.resolve()
            }), n.promise
        },
        nt = function() {
            var n = t.defer(),
                i = a();
            return h.createDefinition(i).then(function(t) {
                var i = t.data;
                c.success("保存成功");
                e.workflowDefinitionDic.clearCache();
                f.close(i);
                n.resolve()
            }), n.promise
        },
        tt = {
            money: "元",
            percent: "%"
        },
        it = function() {
            var n = [];
            return n.push(e.workflowOperatorDic.load().then(function(n) {
                i.workflowOperatorDict = n
            })), n.push(e.workflowCondFieldDic.load().then(function(n) {
                i.workflowCondFields = n
            })), n.push(e.workflowApprovalProviderDic.loadActive().then(function(n) {
                _.each(n, function(n) {
                    n.displayName = n.officeId == l.officeId ? n.name : n.name + "(" + n.officeAbbreviation + ")"
                });
                i.allProviders = n
            })), t.all(n)
        },
        v = function(n) {
            return n.fieldTypeName == "money" || n.fieldTypeName == "percent" ? 0 : n.fieldTypeName == "event" ? 1 : ""
        },
        y = function(n) {
            return n == i.workflowTypeEnums.Charge || n == i.workflowTypeEnums.ProcurementPay || n == i.workflowTypeEnums.ChargeCreate || n == i.workflowTypeEnums.ChargeBilledUpdate
        },
        p = function(n) {
            return i.workflowCondFields.filter(function(t) {
                return t.workflowType == n
            })
        },
        w = function() {
            i.providers = i.allProviders;
            _.each(i.providers, function(n) {
                n.actorId = n.userId;
                n.actorName = n.name;
                _.isNull(n.job) && (n.job = "");
                _.isNull(n.employeeNo) && (n.employeeNo = "");
                _.isNull(n.officeAbbreviation) && (n.officeAbbreviation = "")
            })
        },
        rt = function() {
            var n = i.itemInfo ? i.itemInfo.workflowType : i.workflowTypes[0].workflowType,
                t;
            i.hasWorkflowConds = y(n);
            i.currentWorkflowCondFields = p(n);
            w(n);
            i.itemInfo ? i.itemInfo.conds && i.itemInfo.conds.length > 0 && i.itemInfo.conds.forEach(function(n) {
                if (n.operator == 7) {
                    var t = n.benchmark.split(",");
                    t = t.length > 1 ? t : [0, 9999999];
                    n.benchmark = t[0];
                    n.benchmarkMax = t[1]
                }
            }) : (i.itemInfo = {
                workflowType: n,
                isNeedRemind: !0,
                isEdit: !0,
                condRelation: 0,
                steps: [{
                    stepIndex: 1,
                    isNeedRemind: !0,
                    actors: []
                }]
            }, i.currentWorkflowCondFields.length > 0 && (t = i.currentWorkflowCondFields[0], i.itemInfo.conds = [{
                operator: null,
                fieldCode: t.fieldCode,
                benchmark: v(t),
                benchmarkMax: v(t)
            }]))
        },
        ut = function(n) {
            n && (b(n), k(n))
        },
        b = function(n) {
            var t = _.find(i.currentWorkflowCondFields, function(t) {
                return t.fieldCode == n.fieldCode
            });
            n.fieldName = t.fieldName;
            n.fieldTypeName = t.fieldTypeName;
            n.fieldUnit = tt[n.fieldTypeName];
            n.fieldOperators = _.find(i.workflowOperatorDict, function(t) {
                return t.fieldCode == n.fieldCode
            }).condOperators
        },
        k = function(n) {
            if (n.operator) {
                var t = _.find(n.fieldOperators, function(t) {
                    return t.operatorCode == n.operator
                });
                n.operatorName = t.operatorName
            } else n.operator = n.fieldOperators[0].operatorCode, n.operatorName = n.fieldOperators[0].operatorName
        },
        ft = function() {
            var n, t;
            return !i.itemInfo || i.itemInfo.steps.length == 0 ? "" : (n = i.itemInfo.steps[0].actors, n && n.length > 0 ? (t = n.map(function(n) {
                return n.actorName
            }), t.join("，")) : "")
        },
        et = function(n) {
            _.contains([3, 4, 11, 18], n.workflowType) && (n.isExecutorSelectable = !1)
        };
    (function() {
        i.workflowTypeEnums = s.WorkflowType;
        i.getHasWorkflowConds = y;
        i.getCurrentWorkflowCondFields = p;
        i.close = d;
        i.initApprovers = w;
        i.itemInfo = o.itemInfo;
        i.workflowTypes = o.canAddWorkflowTypes;
        i.initWorkflowInfo = rt;
        i.initWorkflowConfig = it;
        i.initDisplayCondInfo = ut;
        i.getBrowseActorsStr = ft;
        i.initCondFieldDetailInfo = b;
        i.initCondOperatorInfo = k;
        i.updateWorkflowTemplateItem = g;
        i.createWorkflowTemplateItem = nt;
        i.onChange = et
    })()
}]);
workflowModule.directive("workflowApproveConfirmDialogView", ["$log", "$q", "$timeout", "$filter", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/workflow/dialogs/workflow-approve-confirm/workflow-approve-confirm-dialog-view.html",
        link: function(n, t) {
            (function() {})();
            i(function() {
                Ares.centerModal(t.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
workflowModule.controller("WorkflowApproveConfirmDialogCtrl", ["$log", "$q", "$scope", "$timeout", "$modalInstance", "$filter", "host", "aresNotification", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var s = function() {
            u.dismiss("cancel")
        },
        h = function() {
            if (!i.notes && i.isRequireNotes) {
                o.error("备注不能为空");
                return
            }
            u.close(i.notes)
        };
    (function() {
        i.isRequireNotes = e.isRequireNotes;
        i.title = e.title;
        i.cancel = s;
        i.ok = h
    })()
}]);
workflowModule.directive("workflowApproveDetailDialogView", ["$log", "$q", "$timeout", "$filter", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/workflow/dialogs/workflow-approve-detail/workflow-approve-detail-dialog-view.html",
        link: function(n, t) {
            (function() {})();
            i(function() {
                Ares.centerModal(t.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
workflowModule.controller("WorkflowApproveDetailDialogCtrl", ["$log", "$q", "$scope", "$timeout", "$modalInstance", "$filter", "host", "aresNotification", function(n, t, i, r, u, f, e) {
    "use strict";
    var o = function() {
        u.dismiss("cancel")
    };
    (function() {
        i.workflowSteps = e.workflowSteps;
        i.title = e.title;
        i.cancel = o
    })()
}]);
workflowModule.factory("workflowBaseToolUtil", ["$log", "$q", "constants", "aresDialog", function() {
    var n = function(n) {
        switch (n.taskStatus) {
            case 0:
                return "待审批";
            case 1:
                return "已通过";
            case 2:
                return "已拒绝";
            default:
                return "待审批"
        }
    };
    return {
        getWorkflowTaskStatusDescription: n
    }
}]);
workflowModule.directive("workflowManagementApprovalView", ["$log", "$q", "$timeout", "$filter", "$modal", "$injector", "aresDialog", "moduleUtil", "enums", "chargeWorkflowPrint", "chargeSvc", "patientSvc", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "WorkflowManagementApprovalCtrl",
        templateUrl: "/app/workflow/views/workflow-management-approval-view.html",
        link: function(n, r) {
            var a = null,
                y = function() {
                    var u = $(window).height() - 240 - (window.Ares3 ? 20 : 0),
                        n = r.find("#list-body"),
                        t;
                    n.css("height", u);
                    t = {
                        scrollButtons: {
                            enable: !1
                        },
                        autoHideScrollbar: !0,
                        scrollInertia: 150,
                        advanced: {
                            updateOnContentResize: !0
                        }
                    };
                    a == null ? (n.mCustomScrollbar(t), a = n) : a.mCustomScrollbar("update");
                    i(function() {
                        var n = r.find(".action-icon-btn");
                        n.tooltip()
                    }, 100)
                },
                p = function(n) {
                    return n.isCanRecall
                },
                w = function(n) {
                    return n.workflowType == s.WorkflowType.Charge
                },
                b = function(n) {
                    var i = null,
                        t = n.workflowType;
                    Ares.specificOfficeUtil.enter(n.officeId);
                    i = t == s.WorkflowType.Charge || t == s.WorkflowType.ChargeCreate || t == s.WorkflowType.InstructorCharge ? rt(n) : t == s.WorkflowType.ChargeRefund ? ft(n) : t == s.WorkflowType.ChargeOverdueDiscount ? et(n) : t == s.WorkflowType.InventoryTake ? ot(n) : t == s.WorkflowType.ProcurementPay ? st(n) : t == s.WorkflowType.InstructorMedicalRecord ? ct(n) : t == s.WorkflowType.InstructorDrugOrder ? lt(n) : t == s.WorkflowType.ProcurementApply ? vt(n) : t == s.WorkflowType.AdvancePaymentRefund || t == s.WorkflowType.AdvancePaymentTransfer ? at(n) : t == s.WorkflowType.ChargeCancel || t == s.WorkflowType.ChargeBilledUpdate ? ut(n) : t == s.WorkflowType.DentalLab ? yt(n) : ht(n);
                    i ? i.finally(function() {
                        Ares.specificOfficeUtil.exit()
                    }) : Ares.specificOfficeUtil.exit()
                },
                k = function(n) {
                    var t = null;
                    Ares.specificOfficeUtil.enter(n.officeId);
                    d(n).then(function(n) {
                        return t = n, g(t.patientId)
                    }).then(function(i) {
                        Ares.specificOfficeUtil.exit();
                        var r = new h.ChargeWorkflowPrinter,
                            u = {
                                workflow: n,
                                chargeOrder: t,
                                patient: i.data,
                                workflowList: [n]
                            };
                        r.setTemplateBaseData(u).setPrintTemplateInfo({
                            isPrivateTemplate: !0,
                            templateCode: "chargeWorkflow"
                        }, "Custom").setOptions({
                            isNeedBaseData: !0
                        }).print()
                    }, function() {
                        Ares.specificOfficeUtil.exit()
                    })
                },
                d = function(n) {
                    var i = t.defer(),
                        r = n.status,
                        u, f, e;
                    return r == s.WorkflowStatus.Approved || r == s.WorkflowStatus.Rejected ? (u = n.referenceSnapshot, f = JSON.parse(u), i.resolve(f)) : (e = n.referenceId, c.get(e).then(function(n) {
                        i.resolve(n.data)
                    })), i.promise
                },
                g = function(n) {
                    var i = t.defer();
                    return l.getPatient(n).then(function(n) {
                        i.resolve(n)
                    }), i.promise
                },
                nt = function(t) {
                    v("批准", !1).then(function(i) {
                        t.taskNotes = i;
                        n.approve(t)
                    })
                },
                tt = function(t) {
                    v("拒绝", !0).then(function(i) {
                        t.taskNotes = i;
                        n.reject(t)
                    })
                },
                it = function(t) {
                    e.confirm("提示", "是否确定要撤回批准").then(function() {
                        t.taskId = t.recallTaskId;
                        n.revert(t)
                    })
                },
                rt = function(n) {
                    return o.load("charge").then(function() {
                        var t = f.get("chargeBaseDialogUtil");
                        return t.browseChargeWorkflowView(n)
                    })
                },
                ut = function(n) {
                    return o.load("charge").then(function() {
                        var t = f.get("chargeBaseDialogUtil");
                        return t.browseChargeBilledWorkflowView(n)
                    })
                },
                ft = function(n) {
                    return o.load("charge").then(function() {
                        var t = f.get("chargeBaseDialogUtil");
                        return t.browseRefundWorkflowView(n)
                    })
                },
                et = function(n) {
                    return o.load("charge").then(function() {
                        var t = f.get("chargeBaseDialogUtil");
                        return t.browseRepayWorkflowView(n)
                    })
                },
                ot = function(n) {
                    return o.load("supplychain").then(function() {
                        var t = f.get("inventoryTakeOrderUtil");
                        return t.browseWorkflowDialog(n)
                    })
                },
                st = function(n) {
                    return o.load("supplychain").then(function() {
                        var t = f.get("procurementPayOrderUtil");
                        return t.browseWorkflowDialog(n)
                    })
                },
                ht = function(n) {
                    return o.load("charge").then(function() {
                        var t = f.get("chargeBaseDialogUtil");
                        return t.browseExecutingStepWorkflowDialogView(n)
                    })
                },
                ct = function(n) {
                    return o.load("emr").then(function() {
                        var t = f.get("emrUtil");
                        return t.browseWorkflowDialog(n)
                    })
                },
                lt = function(n) {
                    return o.load("patient").then(function() {
                        var t = f.get("patientUtil");
                        return t.broswerDrugOrderWorkflow(n)
                    })
                },
                at = function(n) {
                    return o.load("gift").then(function() {
                        var t = f.get("membershipBaseDialogUtil");
                        return t.showAdvancePaymentWorkflowPreview(n)
                    })
                },
                vt = function(n) {
                    return o.load("supplychain").then(function() {
                        var t = f.get("procurementApplyOrderUtil");
                        return t.browseWorkflowDialog(n)
                    })
                },
                yt = function(n) {
                    return o.load("dentalLab").then(function() {
                        var t = f.get("dentalLabOrderUtil");
                        return t.browseWorkflowDialog(n)
                    })
                },
                v = function(n, t) {
                    var i = u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<workflow-approve-confirm-dialog-view><\/workflow-approve-confirm-dialog-view>",
                        controller: "WorkflowApproveConfirmDialogCtrl",
                        windowClass: "charge-confirm-approve-dialog",
                        resolve: {
                            host: function() {
                                return {
                                    title: n,
                                    isRequireNotes: t
                                }
                            }
                        }
                    });
                    return i.result
                },
                pt = function(n) {
                    var t = [],
                        i, r;
                    return t.push({
                        executorName: n.applicant,
                        actionName: "创建该审批",
                        executionTime: n.applicationTime,
                        notes: ""
                    }), i = angular.copy(n.workflowSteps), _.each(i, function(n) {
                        var i = "",
                            r = n.executorName;
                        switch (n.status) {
                            case 0:
                                n.executors && (i = "待审批", r = n.executors.map(function(n) {
                                    return n.executorName
                                }).join("，"));
                                break;
                            case 1:
                                i = "同意";
                                break;
                            case 2:
                                i = "拒绝"
                        }
                        t.push({
                            executorName: r,
                            actionName: i,
                            executionTime: n.executionTime,
                            notes: n.notes
                        })
                    }), r = u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<workflow-approve-detail-dialog-view><\/workflow-approve-confirm-dialog-view>",
                        controller: "WorkflowApproveDetailDialogCtrl",
                        resolve: {
                            host: function() {
                                return {
                                    title: "审核详情",
                                    workflowSteps: t
                                }
                            }
                        }
                    }), r.result
                },
                wt = function(n) {
                    Ares.sensors.trackDropDownEvent("WorkflowManagementApproval", n)
                };
            (function() {
                n.handleDropdownSelect = wt;
                n.revertTask = it;
                n.rejectTask = tt;
                n.approveTask = nt;
                n.itemBrowse = b;
                n.initView = y;
                n.approveDetail = pt;
                n.canRevert = p;
                n.canPrint = w;
                n.itemPrint = k
            })()
        }
    }
}]);
workflowModule.directive("workflowManagementHomeView", ["$log", "$q", "$timeout", "$filter", "appNav", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/workflow/views/workflow-management-home-view.html",
        link: function(n) {
            var t = function() {
                var t = [new u.TabItem("workflowManagement.approval", "审批管理", "", "workflowManagement.approval"), ];
                n.states = t
            };
            (function() {
                t()
            })()
        }
    }
}]);
workflowModule.directive("workflowSettingApprovalView", ["$log", "$q", "$timeout", "$filter", "$modal", "enums", function(n, t, i, r, u, f) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "WorkflowSettingApprovalCtrl",
        templateUrl: "/app/workflow/views/workflow-setting-approval-view.html",
        link: function(n, t) {
            var e = function(n) {
                    return r("toMoney")(n)
                },
                o = function(t) {
                    var i = n.workflowTemplateList[t];
                    if (i.id) return n.removeTemplateItem(i.id);
                    n.workflowTemplateList.splice(t, 1)
                },
                s = function(t) {
                    var i = u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<workflow-approval-setting-item-view><\/workflow-approval-setting-item-view>",
                        controller: "WorkflowApprovalSettingItemCtrl",
                        windowClass: "modal-800w-dialog",
                        resolve: {
                            host: function() {
                                return {
                                    itemInfo: angular.copy(t),
                                    canAddWorkflowTypes: n.getCanAddWorkflowTypes(t)
                                }
                            }
                        }
                    });
                    i.result.then(function() {
                        n.initWorkflowTemplates()
                    })
                },
                h = function() {
                    var t = u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<workflow-approval-setting-item-view><\/workflow-approval-setting-item-view>",
                        controller: "WorkflowApprovalSettingItemCtrl",
                        windowClass: "modal-800w-dialog",
                        resolve: {
                            host: function() {
                                return {
                                    canAddWorkflowTypes: n.getCanAddWorkflowTypes()
                                }
                            }
                        }
                    });
                    t.result.then(function() {
                        n.initWorkflowTemplates()
                    })
                },
                c = function(t) {
                    var e, u, i, r, o;
                    if (!t || t.steps.length == 0) return "";
                    for (e = [f.WorkflowType.InstructorCharge, f.WorkflowType.InstructorMedicalRecord, f.WorkflowType.InstructorDrugOrder], u = [], i = 0; i < t.steps.length; i++) r = t.steps[i].actors, r && r.length > 0 && (o = r.map(function(i) {
                        if (e.indexOf(t.workflowType) != -1 && i.actorId == -99) return "带教老师";
                        var r = _.find(n.allProviders, function(n) {
                            return i.actorId == n.userId
                        });
                        return r ? r.displayName : i.actorName
                    }), u.push((i + 1).toString() + ". " + o.join("，")));
                    return u
                },
                i = function(n, t) {
                    var i = "";
                    return n == "money" ? i = t ? e(t) : "0.00" : n == "percent" && (i = t ? t : "0"), i
                },
                l = function(n) {
                    var r, u, t, f, e;
                    return n ? (r = "", u = n.fieldUnit || "", n.operator == 7 ? (t = n.benchmark.split(","), t = t.length > 1 ? t : [0, 9999999], f = parseFloat(t[0]), e = t[1], r = "从" + (f ? "(包含) " : " ") + i(n.fieldTypeName, f) + u + (" 到 " + i(n.fieldTypeName, e) + u)) : r = i(n.fieldTypeName, n.benchmark).trim() + u, r) : ""
                },
                a = function() {
                    t.find(".item-action-wrap a").tooltip();
                    var n = t.find(".table-main>table>tbody");
                    n.height(t.parent().height() - 70 - (window.Ares3 ? 0 : 86))
                };
            (function() {
                n.getBrowseActorsStr = c;
                n.getDisplayBenchmark = l;
                n.deleteWorkflowTemplateItem = o;
                n.addWorkflowTemplateItem = h;
                n.editWorkflowTemplateItem = s;
                n.initView = a
            })()
        }
    }
}]);
workflowModule.directive("workflowSettingHomeView", ["$log", "$q", "$timeout", "$filter", "appNav", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/workflow/views/workflow-setting-home-view.html",
        link: function(n) {
            var t = function() {
                var t = [new u.TabItem("workflowSetting.approval", "审批流程配置", "", "setting.approval"), ];
                n.states = t
            };
            (function() {
                t()
            })()
        }
    }
}]);